package main;


import mysql.RequeteSql;

import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QGroupBox;
import com.trolltech.qt.gui.QHBoxLayout;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QPixmap;
import com.trolltech.qt.gui.QVBoxLayout;
import com.trolltech.qt.gui.QWidget;

public class Statistic extends QWidget
{

	private QHBoxLayout layout;
	private QVBoxLayout boxLayoutLogo, boxLayoutStat;
	
	void init()
	{
		boxLayoutLogo = new QVBoxLayout();
		boxLayoutStat = new QVBoxLayout();
		layout = new QHBoxLayout();
	}
	
	
	void placeWidget()
	{
		QLabel labIcone = new QLabel();
		labIcone.setFixedSize(550, 600);
		labIcone.setPixmap(new QPixmap("classpath:api/images/ciprovisfond.png"));
		boxLayoutLogo.addWidget(labIcone);
		boxLayoutStat.addWidget(formuleLayout());
		boxLayoutStat.addWidget(stockLayout());
		layout.addLayout(boxLayoutLogo);
		
		layout.addLayout(boxLayoutStat);
		this.setLayout(layout);
		
	}
	
	
	private QGroupBox formuleLayout()
	{
		String tabColor[] = new String[11];
		
		tabColor[0] = "#de0f0f";
		tabColor[1] = "#140fde";
		tabColor[2] =  "#377b25";
		tabColor[3] =  "#c21af9";
		tabColor[4] =  "#00fff6";
		tabColor[5] =  "#a09fa1";
		tabColor[6] =  "#2fea87";
		tabColor[7] =  "#030f09";
		tabColor[8] = "#026430";
		tabColor[9] = "#fcff00";
		tabColor[10] =  "#fd9c1e";
		
		
		QGroupBox groupeForm = new QGroupBox(tr("FORMULE"));
		ItemviewChart cam1 = new ItemviewChart();
		QVBoxLayout lay = new QVBoxLayout();
		QHBoxLayout formLayBox = new QHBoxLayout();
		//QLabel titre = new QLabel("FORMULE");
		Object ob[][] = RequeteSql.nbrClientEnFoncFormule();
	
		for (int i = 0; i < ob.length; i++)
		{//setStyleSheet("QLabel { background-color : red; color : blue; }");
			QLabel lab = new QLabel();
			lab.setText((String)ob[i][1] + " : " + (Long)ob[i][0] + " Clients");
			lay.addWidget(lab);
			lab.setStyleSheet("QLabel { color : " + tabColor[i] + "}");
			cam1.rempliCamember((String)ob[i][1], String.valueOf((Long)ob[i][0]), tabColor[i], i);
		}
		//formLayBox.addWidget(titre);
		formLayBox.addLayout(lay);
		
		cam1.setFixedSize(220,220);
		
		formLayBox.addWidget(cam1);
		groupeForm.setLayout(formLayBox);
		groupeForm.setFixedHeight(250);
		return groupeForm;
		
	}
	
	
	private QGroupBox stockLayout()
	{
		String tabColor[] = new String[11];
		
		tabColor[0] = "#de0f0f";
		tabColor[1] = "#140fde";
		tabColor[2] =  "#377b25";
		tabColor[3] =  "#c21af9";
		tabColor[4] =  "#00fff6";
		tabColor[5] =  "#a09fa1";
		tabColor[6] =  "#2fea87";
		tabColor[7] =  "#030f09";
		tabColor[8] = "#026430";
		tabColor[9] = "#fcff00";
		tabColor[10] =  "#fd9c1e";
		
		
		
		QGroupBox groupeForm = new QGroupBox(tr("STOCK"));
		ItemviewChart cam = new ItemviewChart();
		QVBoxLayout lay = new QVBoxLayout();
		QHBoxLayout formLayBox = new QHBoxLayout();
		//QLabel titre = new QLabel("FORMULE");
		Object ob[][] = RequeteSql.produitList();
	
		for (int i = 0; i < ob.length; i++)
		{
			QLabel lab = new QLabel();
			lab.setText((String)ob[i][1] + " : " + (Integer)ob[i][3] + " ");
			lay.addWidget(lab);
			lab.setStyleSheet("QLabel { color : " + tabColor[i] + "}");

			cam.rempliCamember((String)ob[i][1], String.valueOf((Integer)ob[i][3]), tabColor[i], i);
		}
		//formLayBox.addWidget(titre);
		formLayBox.addLayout(lay);
		
		cam.setFixedSize(220,220);
		
		formLayBox.addWidget(cam);
		groupeForm.setLayout(formLayBox);
		groupeForm.setFixedHeight(250);
		return groupeForm;
		
	}
	public Statistic()
	{
		RequeteSql.TAP_InitialiserConnectionJDBC();
		init();
		placeWidget();
		
		
		//cam1.setFixedSize(150,150);
		this.setLayout(layout);
		//layout.addWidget(cam1);
		//layout.addWidget(cam2);
		//layout.addWidget(cam3);
		
		
		
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		QApplication.initialize(args);

        Statistic mainW = new Statistic();
        mainW.show();

        QApplication.exec();
	}

}
